package com.uenpay.im.invokeitems.login;

import com.qiyunxin.android.http.net.HttpInvokeItem;
import com.uenpay.im.configuration.APIConfiguration;

import org.json.JSONException;
import org.json.JSONObject;

import java.util.HashMap;

/**
 *
 * @author SL
 * @copyRight http://www.qiyunxin.com
 */
public class RegOrCancelDeviceNoInvokeItem extends HttpInvokeItem {

	public class RegDeviceNoInvokeItemResult {
		public int status;
		public String msg;
		public long timeStamp;
	}

	public RegDeviceNoInvokeItemResult getOutput() {
		return (RegDeviceNoInvokeItemResult) GetResultObject();
	}

	public RegOrCancelDeviceNoInvokeItem(boolean is_cancel) {
		String pattern = "";
		if (is_cancel) {
			pattern = "Chat/Chat/unregDeviceNo?"
					+ APIConfiguration.getCustIdAndToken();
		} else {
			pattern = "Chat/Chat/regDeviceNo?"
					+ APIConfiguration.getCustIdAndToken();
		}
		HashMap<String, String> mRequestParams = new HashMap<String, String>();
		mRequestParams.put("deviceno", "");
		SetRequestParams(mRequestParams);
		String url = APIConfiguration.getBaseUrl() + pattern;
		SetUrl(url);
	}

	@Override
	protected Object DeserializeResult(String responseBody) {
		RegDeviceNoInvokeItemResult result = new RegDeviceNoInvokeItemResult();
		try {
			JSONObject json = new JSONObject(responseBody);
			result.status = json.optInt("status");
			result.msg = json.optString("msg");
		} catch (JSONException e) {
			e.printStackTrace();
			return result;
		}

		return result;
	}
}
